package com.ymttest.business.service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

import com.ymatou.iapi.auth.parameter.SignAuthBean;
import com.ymatou.iapi.auth.service.SignAuthCall;
import com.ymatou.iapi.login.parameter.AliUserRequestDtoBean;
import com.ymatou.iapi.login.parameter.BindAliUserRequestDtoBean;
import com.ymatou.iapi.login.parameter.BindBean;
import com.ymatou.iapi.login.parameter.BindSinaWeiboUserRequestDtoBean;
import com.ymatou.iapi.login.parameter.BindWeiXinUseroRequestDtoBean;
import com.ymatou.iapi.login.parameter.LoginAuthBean;
import com.ymatou.iapi.login.parameter.ThirdpartyLoginBean;
import com.ymatou.iapi.login.parameter.SinaWeiBoUserRequestDtoBean;
import com.ymatou.iapi.login.parameter.UnBindThirdPartyAccountDtoBean;
import com.ymatou.iapi.login.service.AliUserRequestDtoCall;
import com.ymatou.iapi.login.service.BindAliUserRequestDtoCall;
import com.ymatou.iapi.login.service.BindCall;
import com.ymatou.iapi.login.service.BindSinaWeiboUserRequestDtoCall;
import com.ymatou.iapi.login.service.BindWeiXinUseroRequestDtoCall;
import com.ymatou.iapi.login.service.LoginAuthCall;
import com.ymatou.iapi.login.service.ThirdpartyLoginCall;
import com.ymatou.iapi.login.service.SinaWeiBoUserRequestDtoCall;
import com.ymatou.iapi.login.service.UnBindThirdPartyAccountDtoCall;
import com.ymatou.iapi.login.service.WeiXinUserRequestDtoCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.iapi.userservice.parameter.AddressRequestDtoBean;
import com.ymatou.iapi.userservice.parameter.BindEmailBean;
import com.ymatou.iapi.userservice.parameter.ExpChangeBean;
import com.ymatou.iapi.userservice.parameter.LockUserRequestDtoBean;
import com.ymatou.iapi.userservice.parameter.MobileexistsBean;
import com.ymatou.iapi.userservice.parameter.PasswordResetRequestDtoBean;
import com.ymatou.iapi.userservice.parameter.SetNickNameDtoBean;
import com.ymatou.iapi.userservice.parameter.SetRemarkBean;
import com.ymatou.iapi.userservice.parameter.UnBindMobileRequestDtoBean;
import com.ymatou.iapi.userservice.parameter.UpdateTradingPwdBean;
import com.ymatou.iapi.userservice.parameter.enums.AppSourceEnum;
import com.ymatou.iapi.userservice.parameter.enums.ChannelSourceEnum;
import com.ymatou.iapi.userservice.parameter.enums.GenderEnum;
import com.ymatou.iapi.userservice.parameter.enums.TerminalSourceEnum;
import com.ymatou.iapi.userservice.parameter.enums.ThirdPartyTypeEnum;
import com.ymatou.iapi.userservice.parameter.enums.UserTypeEnum;
import com.ymatou.iapi.userservice.parameter.enums.VisitLanguageEnum;
import com.ymatou.iapi.userservice.parameter.req.BindThirdPartyUserReq;
import com.ymatou.iapi.userservice.parameter.req.CreateThirdPartyUserReq;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.parameter.req.SetUserLogoReq;
import com.ymatou.iapi.userservice.parameter.req.UnBindThirdPartyUserReq;
import com.ymatou.iapi.userservice.parameter.resp.AddressResp;
import com.ymatou.iapi.userservice.service.AddressRequestDtoCall;
import com.ymatou.iapi.userservice.service.BindEmailCall;
import com.ymatou.iapi.userservice.service.BindThirdPartyUserCall;
import com.ymatou.iapi.userservice.service.CreateThirdPartyUserCall;
import com.ymatou.iapi.userservice.service.CreateUserCall;
import com.ymatou.iapi.userservice.service.ExpChangeCall;
import com.ymatou.iapi.userservice.service.GAddressRequestDtoCall;
import com.ymatou.iapi.userservice.service.LockUserRequestDtoCall;
import com.ymatou.iapi.userservice.service.MobileexistsCall;
import com.ymatou.iapi.userservice.service.PasswordResetRequestDtoCall;
import com.ymatou.iapi.userservice.service.SetNickNameDtoCall;
import com.ymatou.iapi.userservice.service.SetRemarkCall;
import com.ymatou.iapi.userservice.service.SetUserLogoCall;
import com.ymatou.iapi.userservice.service.UnBindMobileRequestDtoCall;
import com.ymatou.iapi.userservice.service.UnBindThirdPartyUserCall;
import com.ymatou.iapi.userservice.service.UnLockUserRequestDtoCall;
import com.ymatou.iapi.userservice.service.UpdateTradingPwdCall;
import com.ymt.core.tool.Logger;
import com.ymttest.common.enums.UserTerminalSourceEnum;
import com.ymttest.database.sqlwapper.UserSafeWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.AppTypeChannel;

public class JUserCallService {
	/**
	 * 默认初始化创建用户bean
	 * 
	 * @param cur
	 * @return
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	public static CreateUserReq initCreateUserBean(CreateUserReq cur)
			throws ClientProtocolException, IOException {
		if (cur == null) {
			cur = new CreateUserReq();
		}
		cur.setAppId("autotest");
		cur.setChannelSource(ChannelSourceEnum.Other);
		cur.setClientIp(TestDataManager.getRandomIp());
		cur.setDeviceId(TestDataManager.getRandomUUID().toString());
		cur.setEquimentid(TestDataManager.getRandomUUID().toString());
		cur.setLoginId("NewJavaReg_" + TestDataManager.getRandomNum(10));
		cur.setLoginPassword("123456a");
		cur.setMail(TestDataManager.getEmail());

		String moblie = TestDataManager.getPhoneNum();
		if (mobileExists(moblie)) {
			moblie = TestDataManager.getPhoneNum();
		}
		cur.setMobile(moblie);
		cur.setRegSource(AppSourceEnum.App);
		cur.setRequestId(TestDataManager.getRandomUUID().toString());
		cur.setTerminalSource(TerminalSourceEnum.IOS);
		cur.setUserType(UserTypeEnum.Normal);
		cur.setVisitLanguage(VisitLanguageEnum.Chinese);
		return cur;
	}

	/**
	 * 创建用户
	 * 
	 * @param cur
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static Integer createUserCall(CreateUserReq cur)
			throws ClientProtocolException, IOException {
		CreateUserCall CreateUserCall = new CreateUserCall();
		CreateUserCall.setData(false, cur);
		CreateUserCall.callService();
		Integer uid = CreateUserCall.getJsonObject().get("Result")
				.getAsJsonObject().get("UserId").getAsInt();
		return uid;
	}

	/**
	 * 初始化第三方注册,默认weixin
	 * 
	 * @return
	 */
	public static CreateThirdPartyUserReq initCreateThirdUserReq() {
		String randomStr = TestDataManager.getRandomNumToHex(6);
		CreateThirdPartyUserReq req = new CreateThirdPartyUserReq();
		req.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
		req.setChannelSource(ChannelSourceEnum.WeiXin);
		req.setThirdPartyId(randomStr);
		req.setAppSource(AppSourceEnum.App);
		req.setClientIp(TestDataManager.getRandomIp());
		req.setUserGender(GenderEnum.Male);
		req.setHeadimgurl("http://img.ymatou.com/" + randomStr);
		req.setOpenId(randomStr);
		req.setCountry("China");
		req.setProvince("SH");
		req.setCity("SH");
		req.setDeviceId(UUID.randomUUID().toString());
		req.setEquimentid(UUID.randomUUID().toString());
		req.setTerminalSource(TerminalSourceEnum.IOS);
		req.setMobile(TestDataManager.getPhoneNum());
		req.setThirdPartyUserName("uname" + randomStr);
		return req;
	}

	/**
	 * 初始化第三方bind,默认weixin
	 * 
	 * @return
	 */
	public static BindThirdPartyUserReq initBindThirdUserReq(int userId) {

		BindThirdPartyUserReq req = new BindThirdPartyUserReq();

		req.setUserId(userId);
		int randomNum = TestDataManager.getRandomIntNum(9);
		String randomStr = TestDataManager.getRandomNumToHex(6);
		req.setTerminalSource(TerminalSourceEnum.IOS);

		req.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
		req.setThirdPartyId(randomStr);
		req.setAppSource(AppSourceEnum.App);
		req.setClientIp(TestDataManager.getRandomIp());
		req.setUserGender(GenderEnum.Male);
		req.setHeadimgurl("http://img.ymatou.com/" + randomStr);
		req.setOpenId(randomStr);
		req.setCountry("China");
		req.setProvince("SH");
		req.setCity("SH");
		req.setDeviceId(UUID.randomUUID().toString());
		req.setEquimentid(UUID.randomUUID().toString());
		req.setTerminalSource(TerminalSourceEnum.IOS);
		req.setMobile(TestDataManager.getPhoneNum());

		return req;
	}

	/**
	 * 第三方注册
	 * 
	 * @param cur
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static Integer createThirdPartyUserCall(CreateThirdPartyUserReq cur)
			throws ClientProtocolException, IOException {
		CreateThirdPartyUserCall CreateThirdPartyUserCall = new CreateThirdPartyUserCall();
		CreateThirdPartyUserCall.setData(false, cur);
		CreateThirdPartyUserCall.callService();
		Integer uid = CreateThirdPartyUserCall.getJsonObject().get("Result")
				.getAsJsonObject().get("UserId").getAsInt();
		return uid;
	}

	/**
	 * 第三方绑定
	 * 
	 * @param cur
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static Integer bindThirdPartyUserCall(BindThirdPartyUserReq cur)
			throws ClientProtocolException, IOException {
		BindThirdPartyUserCall BindThirdPartyUserCall = new BindThirdPartyUserCall();
		BindThirdPartyUserCall.setData(false, cur);
		BindThirdPartyUserCall.callService();
		Integer uid = BindThirdPartyUserCall.getJsonObject().get("Result")
				.getAsJsonObject().get("UserId").getAsInt();
		return uid;
	}

	/**
	 * 第三方解绑
	 * 
	 * @param cur
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void UnBindThirdPartyUserCall(UnBindThirdPartyUserReq cur)
			throws ClientProtocolException, IOException {
		UnBindThirdPartyUserCall UnBindThirdPartyUserCall = new UnBindThirdPartyUserCall();
		UnBindThirdPartyUserCall.setData(false, cur);
		UnBindThirdPartyUserCall.callService();
	}

	/**
	 * 锁定用户
	 * 
	 * @param UserId
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void lockUsers(Integer userId) throws ClientProtocolException,
			IOException {
		LockUserRequestDtoBean lockuserrequestdtoBean = new LockUserRequestDtoBean();
		LockUserRequestDtoCall lockuserrequestdtoCall = new LockUserRequestDtoCall();
		lockuserrequestdtoBean.setDescription("自动化锁定");
		lockuserrequestdtoBean.setOperating("autoTest");
		ArrayList userids = new ArrayList<>();
		userids.add(userId);
		lockuserrequestdtoBean.setUserId(userids);
		lockuserrequestdtoCall.setData(false, lockuserrequestdtoBean);
		lockuserrequestdtoCall.callService();
		try {
			if(!Boolean.valueOf(lockuserrequestdtoCall.getJsonObject().get("Success").toString())){
				Logger.debug("锁定用户失败" );
			};
		} catch (Exception e) {
			Logger.debug("锁定用户失败:" + e.getMessage());
		}
	}

	/**
	 * 解除锁定用户
	 * 
	 * @param UserId
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static int UnLockUsers(Integer userId)
			throws ClientProtocolException, IOException {
		LockUserRequestDtoBean lockuserrequestdtoBean = new LockUserRequestDtoBean();
		UnLockUserRequestDtoCall unlockuserrequestdtoCall = new UnLockUserRequestDtoCall();
		lockuserrequestdtoBean.setDescription("自动化锁定");
		lockuserrequestdtoBean.setOperating("autoTest");
		ArrayList userids = new ArrayList<>();
		userids.add(userId);
		lockuserrequestdtoBean.setUserId(userids);
		unlockuserrequestdtoCall.setData(false, lockuserrequestdtoBean);
		unlockuserrequestdtoCall.callService();
		int num = 0;
		try {
			num = unlockuserrequestdtoCall.getJsonObject().get("Result")
					.getAsJsonObject().get("UnlockCount").getAsInt();
		} catch (Exception e) {
			Logger.debug("解锁用户失败:" + e.getMessage());
		}
		return num;
	}

	/**
	 * 认证
	 * 
	 * @param sab
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static SignAuthCall signAuth(SignAuthBean sab)
			throws ClientProtocolException, IOException {
		SignAuthCall sac = new SignAuthCall();
		sac.setData(false, sab);
		sac.callService();
		return sac;
	}

	/**
	 * 解绑手机
	 * 
	 * @param ub
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void UnBindMobileCall(UnBindMobileRequestDtoBean ub)
			throws ClientProtocolException, IOException {
		UnBindMobileRequestDtoCall UnBindMobileRequestDtoCall = new UnBindMobileRequestDtoCall();
		UnBindMobileRequestDtoCall.setData(false, ub);
		UnBindMobileRequestDtoCall.callService();
	}

	/**
	 * 设置头像
	 * 
	 * @param SetUserLogoBean
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void SetUserLogoCall(SetUserLogoReq SetUserLogoBean)
			throws ClientProtocolException, IOException {
		SetUserLogoCall SetUserLogoCall = new SetUserLogoCall();
		SetUserLogoCall.setData(false, SetUserLogoBean);
		SetUserLogoCall.callService();
	}
	/**
	 * 快速设置头像
	 * @param userId
	 * @param logoUrl
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void SetUserLogoCall(Integer userId, String logoUrl)
			throws ClientProtocolException, IOException {
		SetUserLogoCall SetUserLogoCall = new SetUserLogoCall();
		SetUserLogoReq SetUserLogoBean = new SetUserLogoReq();
		SetUserLogoBean.setUserId(userId);
		SetUserLogoBean.setLogoUrl(logoUrl);
		SetUserLogoBean.setAppId("AutoTest");
		SetUserLogoBean.setClientIp(TestDataManager.getLocalIp());
		SetUserLogoCall.setData(false, SetUserLogoBean);
		SetUserLogoCall.callService();
	}
	/**
	 * 注册接口bean
	 * 
	 * @return
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	public static UserRegisterInfoRequestDtoBean initUserRegisterInfoRequestDtoBean()
			throws ClientProtocolException, IOException {
		UserRegisterInfoRequestDtoBean userBean = new UserRegisterInfoRequestDtoBean();
		String loginId = "autotest_" + TestDataManager.randomStr(7);
		String loginMail = loginId + "@ymatou.com";
		String moblie = TestDataManager.getPhoneNum();
		if (mobileExists(moblie)) {
			moblie = TestDataManager.getPhoneNum();
		}
		String pas = "123456a";
		//	用户类型：0 - 买家，1 - 买手（商家）
		int registerType = 0;
		Boolean isAgreeContract = true;
		int regSource = 0;
		int visitLan = 0;
		ChannelSourceEnum channelSource = ChannelSourceEnum.Alipay;
		UserTerminalSourceEnum terminalSource = UserTerminalSourceEnum.Android;

		String clientIp = TestDataManager.getRandomIp();

		Long tokenTimeOut = (long) 1;

		userBean.setLoginId(loginId);
		userBean.setLoginMail(loginMail);
		userBean.setLoginMobile(moblie);
		userBean.setPas(pas);
		userBean.setRegisterType(registerType);
		userBean.setIsAgreeContract(isAgreeContract);
		userBean.setRegSource(regSource);
		userBean.setVisitLan(visitLan);
		userBean.setChannelSource(channelSource);
		userBean.setTerminalSource(terminalSource);
		userBean.setClientIp(clientIp);
		userBean.setTokenTimeOut(tokenTimeOut);
		userBean.setEquimentid(TestDataManager.getRandomUUID().toString());
		userBean.setDeviceId(TestDataManager.getRandomUUID().toString());
		return userBean;
	};

	/**
	 * 注册
	 * 
	 * @param urb
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static UserRegisterInfoRequestDtoCall UserRegisterInfoRequestDtoCall(
			UserRegisterInfoRequestDtoBean urb) throws ClientProtocolException,
			IOException {
		UserRegisterInfoRequestDtoCall UserRegisterInfoRequestDtoCall = new UserRegisterInfoRequestDtoCall();
		UserRegisterInfoRequestDtoCall.setData(false, urb);
		UserRegisterInfoRequestDtoCall.callService();
		return UserRegisterInfoRequestDtoCall;
	}

	/**
	 * @param UserName
	 * @param pas
	 * @param sourceType
	 * @param ip
	 * @return
	 * @throws InterruptedException 
	 */
	public static LoginAuthCall login(String UserName, String pas,
			String sourceType, String ip, String did)
			throws InterruptedException {
		LoginAuthBean lab = new LoginAuthBean();
		LoginAuthCall lac = new LoginAuthCall();
		try {
			lab.setLoginId(UserName);
			lab.setPas(pas);
			lab.setSourceType(sourceType);
			lab.setClientIp(ip);
			lab.setDeviceId(did);
			lac.setData(false, lab);
			Logger.comment("用户:" + UserName + "登录");
			lac.callService();
			if (!lac.getSuccess()) {
				Thread.sleep(500);
				lac.callService();
			}
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return lac;
	}

	/**
	 * 初始化阿里账号联合登录Bean
	 * 
	 * 注册需传Mobile 登录需传UserId，且不能传Mobile
	 * 
	 * @param aliUserId
	 * @return
	 */
	public static AliUserRequestDtoBean initAliUserRequestDtoBean() {
		AliUserRequestDtoBean aliuserregbean = new AliUserRequestDtoBean();

		String aliUserId = "ali_" + TestDataManager.getRandomNum(10);
		aliuserregbean.setSAliUserId(aliUserId);
		aliuserregbean.setSRealName("Lily" + TestDataManager.getRandomNum(10));
		aliuserregbean.setSEmail("12456@123.com");
		aliuserregbean.setRegSource(AppSourceEnum.Wap);
		aliuserregbean.setTerminalSource(TerminalSourceEnum.IOS);
		aliuserregbean.setClientIp(TestDataManager.getRandomIp());
		aliuserregbean.setTokenTimeOut((new Date()).getTime());
		aliuserregbean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);

		return aliuserregbean;
	}

	/**
	 * 阿里账号联合登录
	 * 
	 * @param aliUserRequestDtoBean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static AliUserRequestDtoCall aliUserRequestDto(
			AliUserRequestDtoBean aliUserRequestDtoBean)
			throws ClientProtocolException, IOException {
		AliUserRequestDtoCall call = new AliUserRequestDtoCall();
		call.setData(false, aliUserRequestDtoBean);
		call.callService();

		return call;
	}

	/**
	 * 初始化微博注册并登录的Bean
	 * 
	 * 注册需传Mobile 登录需传UserId，且不能传Mobile
	 * 
	 * @return
	 */
	public static SinaWeiBoUserRequestDtoBean initSinaWeiBoUserRequestDtoBean() {
		SinaWeiBoUserRequestDtoBean regBean = new SinaWeiBoUserRequestDtoBean();

		String aliUserId = "ali_" + TestDataManager.getRandomNum(10);
		regBean.setSWeiboUserId(aliUserId);
		regBean.setSName("regAliUser_" + TestDataManager.getRandomNum(6));
		regBean.setSMail("12456@123.com");
		regBean.setRegSource(AppSourceEnum.App);
		regBean.setTerminalSource(TerminalSourceEnum.IOS);
		regBean.setClientIp(TestDataManager.getRandomIp());
		regBean.setTokenTimeOut((new Date()).getTime());
		regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
		regBean.setDeviceId(TestDataManager.getRandomUUID().toString());
		regBean.setEquimentid(TestDataManager.getRandomUUID().toString());
		regBean.setSToken("sToken");

		return regBean;
	}

	/**
	 * 初始化用于微博登录的Bean
	 * 
	 * @return
	 */
	public static SinaWeiBoUserRequestDtoBean initSinaWeiBoUserRequestDtoBeanForRegister() {
		SinaWeiBoUserRequestDtoBean regBean = new SinaWeiBoUserRequestDtoBean();

		String aliUserId = "ali_" + TestDataManager.getRandomNum(10);
		String phone = TestDataManager.getPhoneNum();
		regBean.setSWeiboUserId(aliUserId);
		regBean.setSName("regAliUser_" + TestDataManager.getRandomNum(6));
		regBean.setSMail("12456@123.com");
		regBean.setRegSource(AppSourceEnum.App);
		regBean.setTerminalSource(TerminalSourceEnum.IOS);
		regBean.setClientIp(TestDataManager.getRandomIp());
		regBean.setTokenTimeOut((new Date()).getTime());
		regBean.setMobile(phone);
		regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
		regBean.setDeviceId(TestDataManager.getRandomUUID().toString());
		regBean.setEquimentid(TestDataManager.getRandomUUID().toString());
		regBean.setSToken("sToken");

		return regBean;
	}

	/**
	 * 微博联合登录请求
	 * 
	 * @param bean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static SinaWeiBoUserRequestDtoCall sinaWeiBoUserRequestDto(
			SinaWeiBoUserRequestDtoBean bean) throws ClientProtocolException,
			IOException {
		SinaWeiBoUserRequestDtoCall call = new SinaWeiBoUserRequestDtoCall();
		call.setData(false, bean);
		call.callService();

		return call;

	}

	public static com.ymatou.iapi.login.parameter.WeiXinUserRequestDtoBean initWeiXinUserRequestDtoBean() {
		com.ymatou.iapi.login.parameter.WeiXinUserRequestDtoBean regBean = new com.ymatou.iapi.login.parameter.WeiXinUserRequestDtoBean();

		String wxId = "wx_" + TestDataManager.getRandomNum(10);
		regBean.setUnionId(wxId);
		regBean.setName("regwx_" + TestDataManager.getRandomNum(6));
		regBean.setRegSource(AppSourceEnum.App);

		regBean.setClientIp(TestDataManager.getRandomIp());

		regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
		regBean.setDeviceId(TestDataManager.getRandomUUID().toString());
		regBean.setEquimentid(TestDataManager.getRandomUUID().toString());
		regBean.setTokenSource("tokenSource");
		// regBean.setTSource(TerminalSourceEnum.PC);
		regBean.setCountry("China");
		regBean.setProvince("Shanghai");
		regBean.setCity("City");
		regBean.setHeadimgurl("Headimgurl");
		regBean.setOId("openId_" + TestDataManager.getRandomNum(10));
		regBean.setSex("Femail");
		regBean.setTimeOut(new Date().getTime());
		regBean.setTSource(TerminalSourceEnum.PC);
		regBean.setWeixinToken("weixintoken_" + TestDataManager.getRandomNum(4));

		return regBean;
	}

	public static com.ymatou.iapi.login.parameter.WeiXinUserRequestDtoBean initWeiXinUserRequestDtoBeanForRegister() {
		com.ymatou.iapi.login.parameter.WeiXinUserRequestDtoBean regBean = new com.ymatou.iapi.login.parameter.WeiXinUserRequestDtoBean();

		String wxId = "wx_" + TestDataManager.getRandomNum(10);
		String phone = TestDataManager.getPhoneNum();
		regBean.setUnionId(wxId);
		regBean.setName("regwx_" + TestDataManager.getRandomNum(6));
		regBean.setRegSource(AppSourceEnum.App);

		regBean.setClientIp(TestDataManager.getRandomIp());

		regBean.setMobile(phone);
		regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
		regBean.setDeviceId(TestDataManager.getRandomUUID().toString());
		regBean.setEquimentid(TestDataManager.getRandomUUID().toString());
		regBean.setTokenSource("tokenSource");
		// regBean.setTSource(TerminalSourceEnum.PC);
		regBean.setCountry("Country");
		regBean.setProvince("Province");
		regBean.setCity("City");
		regBean.setHeadimgurl("Headimgurl");
		regBean.setOId("openId_" + TestDataManager.getRandomNum(10));

		return regBean;
	}

	/**
	 * 微信联合认证
	 * 
	 * @param bean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static WeiXinUserRequestDtoCall weiXinUserRequestDto(
			com.ymatou.iapi.login.parameter.WeiXinUserRequestDtoBean bean)
			throws ClientProtocolException, IOException {
		WeiXinUserRequestDtoCall call = new WeiXinUserRequestDtoCall();
		call.setData(false, bean);
		call.callService();

		return call;
	}

	/**
	 * 初始化绑定阿里账号Bean
	 * 
	 * @param token
	 * @return
	 */
	public static BindAliUserRequestDtoBean initBindAliUserRequestDtoBean(
			String token) {
		BindAliUserRequestDtoBean bindAliUserRequestDtoBean = new BindAliUserRequestDtoBean();

		String ali = "NewBindAli_" + TestDataManager.getRandomNum(10);

		bindAliUserRequestDtoBean.setToken(token);
		bindAliUserRequestDtoBean.setClientType("mainsite");

		AliUserRequestDtoBean aliUserRequestDtoBean = initAliUserRequestDtoBean();
		aliUserRequestDtoBean.setSAliUserId(ali);
		bindAliUserRequestDtoBean.setAliUser(aliUserRequestDtoBean);

		return bindAliUserRequestDtoBean;
	}

	/**
	 * 绑定阿里账号
	 * 
	 * @param bindAliUserRequestDtoBean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static BindAliUserRequestDtoCall BindAliUserRequestDto(
			BindAliUserRequestDtoBean bindAliUserRequestDtoBean)
			throws ClientProtocolException, IOException {
		BindAliUserRequestDtoCall BindAliUserRequestDtoCall = new BindAliUserRequestDtoCall();
		BindAliUserRequestDtoCall.setData(false, bindAliUserRequestDtoBean);
		BindAliUserRequestDtoCall.callService();

		return BindAliUserRequestDtoCall;
	}

	public static BindSinaWeiboUserRequestDtoBean initBindSinaWeiboUserRequestDtoBean(
			String token) {
		BindSinaWeiboUserRequestDtoBean bindsinaweibouserrequestdtoBean = new BindSinaWeiboUserRequestDtoBean();

		String weiboUserId = "NewBindWeibo_" + TestDataManager.getRandomNum(10);
		bindsinaweibouserrequestdtoBean.setToken(token);
		bindsinaweibouserrequestdtoBean.setClientType("mainsite");

		SinaWeiBoUserRequestDtoBean sinaWeiBoUserRequestDtoBean = initSinaWeiBoUserRequestDtoBean();
		sinaWeiBoUserRequestDtoBean.setSWeiboUserId(weiboUserId);

		bindsinaweibouserrequestdtoBean
				.setWeiBoUser(sinaWeiBoUserRequestDtoBean);

		return bindsinaweibouserrequestdtoBean;
	}

	/**
	 * 新浪微博联合登陆
	 * 
	 * @param bindSinaWeiboUserRequestDtoBean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static BindSinaWeiboUserRequestDtoCall bindSinaWeiboUserRequestDto(
			BindSinaWeiboUserRequestDtoBean bindSinaWeiboUserRequestDtoBean)
			throws ClientProtocolException, IOException {
		BindSinaWeiboUserRequestDtoCall call = new BindSinaWeiboUserRequestDtoCall();
		call.setData(false, bindSinaWeiboUserRequestDtoBean);
		call.callService();

		return call;
	}

	/**
	 * 设置绑定微信默认bean
	 * 
	 * @param token
	 * @return
	 */
	public static BindWeiXinUseroRequestDtoBean initBindWeiXinUseroRequestDtoBean(
			String token) {
		BindWeiXinUseroRequestDtoBean bindweixinuserorequestdtoBean = new BindWeiXinUseroRequestDtoBean();

		bindweixinuserorequestdtoBean.setToken(token);
		bindweixinuserorequestdtoBean.setClientType("mainsite");

		com.ymatou.iapi.login.parameter.WeiXinUserRequestDtoBean weiXinUserRequestDtoBean = initWeiXinUserRequestDtoBean();
		bindweixinuserorequestdtoBean.setWeiXinUser(weiXinUserRequestDtoBean);

		return bindweixinuserorequestdtoBean;
	}

	/**
	 * 绑定微信
	 * 
	 * @param bean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static BindWeiXinUseroRequestDtoCall bindWeiXinUseroRequestDto(
			BindWeiXinUseroRequestDtoBean bean) throws ClientProtocolException,
			IOException {
		BindWeiXinUseroRequestDtoCall call = new BindWeiXinUseroRequestDtoCall();
		call.setData(false, bean);
		call.callService();

		return call;
	}

	/**
	 * 设置解绑第三方账号默认Bean
	 * 
	 * @param thirdPartyId
	 * @param thirdPartyType:Enum
	 *            ThirdPartyType
	 * @param userId
	 * @return
	 */
	public static UnBindThirdPartyAccountDtoBean initUnBindThirdPartyAccountDtoBean(
			String thirdPartyId, String thirdPartyType, Integer userId) {
		UnBindThirdPartyAccountDtoBean unbindthirdpartyaccountdtoBean = new UnBindThirdPartyAccountDtoBean();

		unbindthirdpartyaccountdtoBean.setThirdPartyId(thirdPartyId);
		unbindthirdpartyaccountdtoBean.setThirdPartyType(thirdPartyType);
		unbindthirdpartyaccountdtoBean.setUserId(userId);
		return unbindthirdpartyaccountdtoBean;
	}

	/**
	 * 解绑第三方账号
	 * 
	 * @param unBindThirdPartyAccountDtoBean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static UnBindThirdPartyAccountDtoCall unBindThirdPartyAccountDto(
			UnBindThirdPartyAccountDtoBean unBindThirdPartyAccountDtoBean)
			throws ClientProtocolException, IOException {
		UnBindThirdPartyAccountDtoCall unBindThirdPartyAccountDtoCall = new UnBindThirdPartyAccountDtoCall();
		unBindThirdPartyAccountDtoCall.setData(false,
				unBindThirdPartyAccountDtoBean);
		unBindThirdPartyAccountDtoCall.callService();

		return unBindThirdPartyAccountDtoCall;
	}

	public static Boolean mobileExists(String mobile)
			throws ClientProtocolException, IOException {
		MobileexistsBean mobileexistsBean = new MobileexistsBean();
		MobileexistsCall mobileexistsCall = new MobileexistsCall();
		mobileexistsBean.setMobile(mobile);
		mobileexistsCall.setData(false, mobileexistsBean);
		mobileexistsCall.callService();
		return Boolean.valueOf(mobileexistsCall.getResultData().getResult()
				.getExists());
	}

	/**
	 * 第三方用户登入
	 * 注册需传mobile
	 * 
	 * @return
	 */
	public static ThirdpartyLoginBean initLoginBean() {
		ThirdpartyLoginBean loginBean = new ThirdpartyLoginBean();

		loginBean.setThirdPartyType(ThirdPartyTypeEnum.QQ);
		loginBean.setThirdPartyId("QQ_" + TestDataManager.getRandomNum(10));
		loginBean.setThirdPartyUserName("小鱼儿_"
				+ TestDataManager.getRandomNum(10));
		loginBean.setMail("tony@ymatou.com");
		loginBean.setAppSource(AppSourceEnum.App);
		loginBean.setTerminalSource(TerminalSourceEnum.Android);
		loginBean.setClientIp(TestDataManager.getRandomIp());
		loginBean.setDeviceId(TestDataManager.getRandomUUID().toString());
		loginBean.setDid(TestDataManager.getRandomUUID().toString());

		return loginBean;
	}
	/**
	 * 用户登入bean
	 * @param regbean
	 * @return
	 */
	public static LoginAuthBean initLoginAuthBean(UserRegisterInfoRequestDtoBean regbean) {
		LoginAuthBean lab = new LoginAuthBean();
		lab.setLoginId(regbean.getLoginId());
		lab.setPas(regbean.getPas());
		lab.setSourceType("app");
		lab.setClientIp(regbean.getClientIp());
		lab.setTSource("ios");
		lab.setTokenSource("app");
		lab.setDeviceId(regbean.getDeviceId());
		return lab;
	}
	/**
	 * 用户登入
	 * @param loginBean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static LoginAuthCall loginAuth(LoginAuthBean loginBean)
			throws ClientProtocolException, IOException {
		LoginAuthCall loginCall = new LoginAuthCall();
		loginCall.setData(false, loginBean);
		loginCall.callService();
		return loginCall;
	}
	/**
	 * 第三方用户登入
	 * @param loginBean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static ThirdpartyLoginCall login(ThirdpartyLoginBean loginBean)
			throws ClientProtocolException, IOException {
		ThirdpartyLoginCall loginCall = new ThirdpartyLoginCall();

		loginCall.setData(false, loginBean);
		loginCall.callService();

		return loginCall;
	}

	public static BindBean initBindBean(String token) {
		BindBean bindBean = new BindBean();

		bindBean.setToken(token);
		bindBean.setClientType("mainsite");
		bindBean.setThirdPartyType(ThirdPartyTypeEnum.QQ);
		bindBean.setThirdPartyId("Login_" + TestDataManager.getRandomNum(10));
		bindBean.setThirdPartyUserName("小鱼儿");
		bindBean.setMail("tony@ymatou.com");
		bindBean.setAppSource(AppSourceEnum.App);
		bindBean.setTerminalSource(TerminalSourceEnum.Android);
		bindBean.setClientIp(TestDataManager.getRandomIp());
		bindBean.setDeviceId(TestDataManager.getRandomUUID().toString());
		bindBean.setDid(TestDataManager.getRandomUUID().toString());

		return bindBean;
	}

	public static ThirdpartyLoginBean getLoginBean(BindBean bindBean) {
		ThirdpartyLoginBean loginBean = new ThirdpartyLoginBean();

		loginBean.setThirdPartyType(bindBean.getThirdPartyType());
		loginBean.setThirdPartyId(bindBean.getThirdPartyId());
		loginBean.setThirdPartyUserName(bindBean.getThirdPartyUserName());
		loginBean.setMail(bindBean.getMail());
		loginBean.setAppSource(bindBean.getAppSource());
		loginBean.setTerminalSource(bindBean.getTerminalSource());
		loginBean.setClientIp(bindBean.getClientIp());
		loginBean.setDeviceId(bindBean.getDeviceId());
		loginBean.setDid(bindBean.getDid());

		return loginBean;
	}

	public static BindCall Bind(BindBean bindBean)
			throws ClientProtocolException, IOException {
		BindCall call = new BindCall();

		call.setData(false, bindBean);
		call.callService();

		return call;
	}

	/**
	 * 初始化数据库配置 无用 废弃
	 * 
	 * @throws InterruptedException
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	@Deprecated
	public static void initUserSafeConfig() throws InterruptedException,
			ClientProtocolException, IOException {
		UserSafeWapper authWapper = new UserSafeWapper();
		// 买家用户总开关
		authWapper
				.updateNewLoginSafeConfiguration("Buyer", "Safe", "Open", "1");
		// 买家Token90天开关
		authWapper.updateNewLoginSafeConfiguration("Buyer", "Token", "Open",
				"1");
		// ?开启设备
		authWapper.updateNewLoginSafeConfiguration("Buyer", "Device", "Open",
				"1");
		// 买家设备号黑名单开关
		authWapper.updateNewLoginSafeConfiguration("Buyer", "DeviceBlacklist",
				"Open", "1");
		// 买家密码登入开关
		authWapper.updateNewLoginSafeConfiguration("Buyer", "LoginPas", "Open",
				"1");
		// 买家设备号常用IP区域
		authWapper.updateNewLoginSafeConfiguration("Buyer", "IpOften", "Open",
				"1");
		// 买家是否开启常用设备
		authWapper.updateNewLoginSafeConfiguration("Buyer", "OftenDevice",
				"Open", "1");
		// 商家用户总开关
		authWapper.updateNewLoginSafeConfiguration("Seller", "Safe", "Open",
				"1");
		// 商家用户密码登入次数开关
		authWapper.updateNewLoginSafeConfiguration("Seller", "LoginPas",
				"Open", "1");
		// 商家用户IP黑名单登入次数开关
		authWapper.updateNewLoginSafeConfiguration("Seller", "IpBlacklist",
				"Open", "1");
		// 商家用户IP区域开关
		authWapper.updateNewLoginSafeConfiguration("Seller", "IpOften", "Open",
				"1");
		// 商家用户Token90天开关
		authWapper.updateNewLoginSafeConfiguration("Seller", "Token", "Open",
				"1");
		// 商家用户设备号开关
		authWapper.updateNewLoginSafeConfiguration("Seller", "Device", "Open",
				"1");
		// 商家用户设备号黑名单开关
		authWapper.updateNewLoginSafeConfiguration("Seller", "Deviceblacklist",
				"Open", "1");
	}

	/**
	 * 更新交易密码
	 * 
	 * @param mobile
	 * @param uid
	 * @param newpasswd
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void UpdateTradingPwd(int uid, String newpasswd)
			throws ClientProtocolException, IOException {
		UpdateTradingPwdBean updadetradingpwdbean = new UpdateTradingPwdBean();
		UpdateTradingPwdCall updatetradingpwdcall = new UpdateTradingPwdCall();
		updadetradingpwdbean.setAType("ByUserId");
		//		updadetradingpwdbean.setLoginMobile(mobile);
		updadetradingpwdbean.setNewPassword(newpasswd);
		updadetradingpwdbean.setOldPassword(null);
		updadetradingpwdbean.setPasActionType("ModifyTradingPassword");
		updadetradingpwdbean.setUserId(uid);
		updatetradingpwdcall.setData(false, updadetradingpwdbean);
		updatetradingpwdcall.callService();
	}

	/**
	 * 更新登入密码
	 * @param uid
	 * @param newpasswd
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void UpdateLoginPwd(int uid, String newpasswd)
			throws ClientProtocolException, IOException {
		PasswordResetRequestDtoBean passwordresetrequestdtoBean = new PasswordResetRequestDtoBean();
		PasswordResetRequestDtoCall passwordresetrequestdtoCall = new PasswordResetRequestDtoCall();
		passwordresetrequestdtoBean.setUserId(uid);
		passwordresetrequestdtoBean.setNewPassword(newpasswd);
		passwordresetrequestdtoCall.setData(false, passwordresetrequestdtoBean);
		passwordresetrequestdtoCall.callService();
	}

	/**
	 * 修改昵称
	 * @param uid
	 * @param nickName
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void SetNickName(int uid, String nickName)
			throws ClientProtocolException, IOException {
		SetNickNameDtoBean setnicknamedtoBean = new SetNickNameDtoBean();
		SetNickNameDtoCall setnicknamedtoCall = new SetNickNameDtoCall();
		setnicknamedtoBean.setUserId(uid);
		setnicknamedtoBean.setNickName(nickName);
		setnicknamedtoCall.setData(false, setnicknamedtoBean);
		setnicknamedtoCall.callService();
	}
	/**
	 * 绑定邮件
	 * @param uid
	 * @param email
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void BindEmail(Integer uid, String email)
			throws ClientProtocolException, IOException {
		BindEmailBean BindEmailBean = new BindEmailBean();
		BindEmailCall BindEmailCall = new BindEmailCall();
		BindEmailBean.setEmail(email);
		BindEmailBean.setUserId(uid);
		BindEmailCall.setData(false, BindEmailBean);
		BindEmailCall.callService();
	}
	/**
	 * 初始化地址bean 默认添加 setAction可以设置为 "Add" "Update" "SetDefault" "MarkDelete";
	 * @param uid
	 * @return
	 */
	public static AddressRequestDtoBean initAddressBean(int uid) {
		AddressRequestDtoBean address = new AddressRequestDtoBean();
		address.setiAddressId(1);
		address.setiUserid(uid);
		address.setsAddressCode("100101");
		address.setsBaseAddress(TestDataManager.getRandomNum(5)+":autotest:" + uid);
		address.setsDetailAddress(TestDataManager.getRandomNum(5)+":autotest:" + uid);
		address.setiAction(0);
		address.setsPostCode("100100");
		address.setsTelphone("100100");
		address.setsMobilePhone(TestDataManager.getPhoneNum());
		address.setsRecipient("autotest");
		address.setsEmail("autotest@ymatou.com");
		address.setbIsDefault(false);
		address.setbXloboChecked(false);
		address.setAction("Add");
		return address;
	}
	/**
	 * 返回Result addressid
	 * @param addressBean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws JSONException
	 */
	public static String AddressRequestDtoCall(AddressRequestDtoBean addressBean)
			throws ClientProtocolException, IOException, JSONException {
		Logger.comment(addressBean.getiUserid()+":操作地址服务:"+addressBean.getAction());
		AddressRequestDtoCall gac = new AddressRequestDtoCall();
		gac.setData(false, addressBean);
		gac.callService();
		return gac.getString("Result");
	}
	public static List<AddressResp> getAddressInfoList(int uid)
			throws ClientProtocolException, IOException, JSONException {

		AddressRequestDtoBean arb = new AddressRequestDtoBean();
		arb.setiUserid(uid);
		GAddressRequestDtoCall gac = new GAddressRequestDtoCall();
		gac.setData(false, arb);
		gac.callService();
		return gac.getAddressList();

		/*		UserRequestDtoBean userrequestdtoBean = new UserRequestDtoBean();
				UserRequestDtoCall userrequestdtoCall = new UserRequestDtoCall();
				userrequestdtoBean.setIUserId(uid);

				userrequestdtoCall.setData(FormatUtil.beanToHttpString(
						userrequestdtoBean, true, false));
				userrequestdtoCall.callService();

				return userrequestdtoCall.getResult();*/

	}

	/**
	 * 设置个人简介
	 * @param uid
	 * @param remark
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void SetRemark(Integer uid, String remark)
			throws ClientProtocolException, IOException {
		SetRemarkBean setremarkBean = new SetRemarkBean();
		SetRemarkCall setremarkCall = new SetRemarkCall();
		setremarkBean.setRemark(remark);
		setremarkBean.setUserId(uid);
		setremarkCall.setData(false, setremarkBean);
		setremarkCall.callService();
	}

	/**
	 * 修改用户等级
	 * @param uid
	 * @param level
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void ExpChange(Integer uid, Integer level)
			throws ClientProtocolException, IOException {
		ExpChangeBean ExpChangeBean = new ExpChangeBean();
		ExpChangeCall ExpChangeCall = new ExpChangeCall();
		ExpChangeBean.setExp(1);
		ExpChangeBean.setUserId(uid);
		ExpChangeBean.setLevel(level);
		ExpChangeCall.setData(false, ExpChangeBean);
		ExpChangeCall.callService();
	}
}
